import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Index',
    redirect: '/home',
    component: () => import('@/components/product/Index'),
    children: [
      {
        path: '/home',
        name: 'home',
        component: Home,
        meta: {
          title: '主页',
          flag: false,
        }
      },
      {
        path: '/shop/index',
        name: 'shop',
        component: () => import('@/components/shop/index'),
        meta: {
          title: '商品管理',
          flag: true,
        }
      },
      {
        path: '/shop/detail',
        name: 'shopDetail',
        component: () => import('@/components/shop/detail'),
        meta: {
          title: '商品详情',
          flag: true,
        }
      },
      {
        path: '/shop/edit',
        name: 'shopEdit',
        component: () => import('@/components/shop/edit'),
        meta: {
          title: '商品管理--商品修改',
          flag: true,
        }
      },
      {
        path: '/shop/add',
        name: 'addShop',
        component: () => import('@/components/shop/add'),
        meta: {
          title: '商品管理--商品添加',
          flag: true,
        }
      },
      {
        path: '/classify/index',
        name: 'classify',
        component: () => import('@/components/classify/index'),
        meta: {
          title: '分类管理',
          flag: true,
        }
      },
      {
        path: '/classify/index/add',
        name: 'add',
        component: () => import('@/components/classify/add'),
        meta: {
          title: '品类管理 -- 添加品类',
          flag: true,
        }
      },
      {
        path: '/classify/index/:id',
        name: 'classifyChild',
        component: () => import('@/components/classify/child'),
        meta: {
          title: '分类管理',
          flag: true,
        }
      },
      {
        path: '/order/index',
        name: 'order',
        component: () => import('@/components/order/index'),
        meta: {
          title: '订单管理',
          flag: true,
        }
      },
      {
        path: '/order/detail',
        name: 'order',
        component: () => import('@/components/order/detail'),
        meta: {
          title: '订单详情',
          flag: true,
        }
      },
      {
        path: '/user/index',
        name: 'user',
        component: () => import('@/components/user/index'),
        meta: {
          title: '用户管理',
          flag: true,
        }
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/components/login/login')
  }
]



const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  if (typeof (location) == "string") {
    var Separator = "&";
    if (location.indexOf('?') == -1) { Separator = '?'; }
    location = location + Separator + "random=" + Math.random();
  }
  return routerPush.call(this, location).catch(error => error)
}

const router = new VueRouter({
  routes
})
export default router
